package com.ys.erp.entity.data.bean;

import com.alibaba.fastjson2.JSON;
import com.baomidou.mybatisplus.annotation.*;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;

import java.time.LocalDateTime;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author lwj
 * @date 2025/7/24
 */

/**
 * 用户强烈投诉表
 */
@Data
@TableName(value = "t_strong_complaint")
public class StrongComplaint {
    /**
     * 主键
     */
    @TableId(value = "id", type = IdType.AUTO)
    private Long id;

    /**
     * 投诉单号
     */
    @TableField(value = "complaint_no")
    private String complaintNo;

    @TableField(value = "rela_no")
    private String relaNo;

    /**
     * 用户id
     */
    @TableField(value = "user_id")
    private Long userId;

    /**
     * 投诉内容
     */
    @TableField(value = "complaint_content")
    private String complaintContent;

    /**
     * 投诉图片附件
     */
    @TableField(value = "complaint_image")
    private String complaintImage = "[]";

    /**
     * GOODS_ORDER:商城订单，PET_ORDER:宠物订单
     */
    @TableField(value = "complaint_type")
    private String complaintType;

    /**
     * 联系手机号
     */
    @TableField(value = "phone")
    private String phone;

    /**
     * 状态，UN_DIS:待处理，DIS_START:开始处理，DIS_OK:已完成处理，DIS_SOLVE:已解决，DIS_UN_SOLVE:未解决
     */
    @TableField(value = "complaint_status")
    private String complaintStatus;

    /**
     * 投诉初始化时间
     */
    @TableField(value = "init_time")
    private LocalDateTime initTime;

    /**
     * 开始处理时间
     */
    @TableField(value = "start_time")
    private LocalDateTime startTime;

    /**
     * 处理完成时间
     */
    @TableField(value = "ok_time")
    private LocalDateTime okTime;

    /**
     * 最终已解决未解决时间
     */
    @TableField(value = "over_time")
    private LocalDateTime overTime;

    /**
     * 处理人id
     */
    @TableField(value = "dis_emp_id")
    private Long disEmpId;

    /**
     * 处理人名字
     */
    @TableField(value = "dis_emp_name")
    private String disEmpName;

    /**
     * 处理问题方案
     */
    @TableField(value = "complaint_plan")
    private String complaintPlan;

    @TableField(value = "version")
    @Version
    private Integer version;

    @TableField(value = "create_time")
    private LocalDateTime createTime;

    @TableField(value = "update_time", update = "now()")
    private LocalDateTime updateTime;

    public List<String> getComplaintImageList() {
        return JSON.parseArray(this.complaintImage, String.class);
    }

    @AllArgsConstructor
    @Getter
    public enum Enums {

        GOODS_ORDER,
        PET_ORDER,

        UN_DIS,
        DIS_START,
        DIS_OK,
        DIS_SOLVE,
        DIS_UN_SOLVE
        ,

    }

    public static final Map<String, String> ENUM_MAP = new HashMap<>();

    static {
        ENUM_MAP.put(StrongComplaint.Enums.GOODS_ORDER.toString(), "商品订单问题");
        ENUM_MAP.put(StrongComplaint.Enums.PET_ORDER.toString(), "宠物订单问题");
        ENUM_MAP.put(StrongComplaint.Enums.UN_DIS.toString(), "待处理");
        ENUM_MAP.put(StrongComplaint.Enums.DIS_START.toString(), "开始处理");
        ENUM_MAP.put(StrongComplaint.Enums.DIS_OK.toString(), "处理完成");
        ENUM_MAP.put(StrongComplaint.Enums.DIS_SOLVE.toString(), "已解决");
        ENUM_MAP.put(StrongComplaint.Enums.DIS_UN_SOLVE.toString(), "未解决");
    }

    public String getRandOrderNo() {
        Calendar calendar = Calendar.getInstance();
        int month = calendar.get(Calendar.MONTH) + 1;
        int day = calendar.get(Calendar.DATE);
        return  "c"
                + calendar.get(Calendar.YEAR)
                + (month >= 10 ? String.valueOf(month) : "0" + month)
                + (day >= 10 ? String.valueOf(day) : "0" + day)
                + calendar.get(Calendar.HOUR_OF_DAY)
                + calendar.get(Calendar.MINUTE)
                + calendar.get(Calendar.SECOND)
                + ((int)((Math.random()*9+1)*100000));
    }

}